package com.itmg.factory;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import com.itmg.dao.CategoryDAO;

public class SpringBeanFactory {
	private static BeanFactory beanFactory;
	private static BeanFactory clientBeanFactory;
	static{
		try {
			Resource cresource = new ClassPathResource("applicationContext.xml");
			beanFactory = new XmlBeanFactory(cresource);
		} catch (Exception e) {
			e.printStackTrace();
		}
		try {
			Resource clientCresource = new ClassPathResource("appClientContext.xml");
			clientBeanFactory = new XmlBeanFactory(clientCresource);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public static Object getBeanByID(String beanID) {
		return beanFactory.getBean(beanID);
	}
	public static Object getRemoteBeanByID(String beanID) {
		return clientBeanFactory.getBean(beanID);
	}
	
	public static void main(String[] args) {
		CategoryDAO dao = (CategoryDAO)SpringBeanFactory.getBeanByID("categoryDAO");
		System.out.println(dao);
	}
}
